<?php
class showBannerWidget extends CWidget{
    
    public $area;
    public $object;
    public $type;
    public $template;
    public function run(){
        $templates = array(
            1 => 'home_1_banner',
            2 => 'detail_left_banner',
            3 => 'news_2_banner',
            4 => 'home_3_banner',
            5 => 'detail_right_banner',
            6 => 'slider_banner',
            7 => 'news_right'
        );
        //get banner based on type object
        $criteria = new CDbCriteria();
        $criteria->addCondition("object=:object");
        $criteria->addCondition("type=:type");
        $criteria->addCondition("area=:area");
        $criteria->order = 'area ASC,orders ASC';
        $criteria->params = array(':object' => $this->object,':type' => $this->type,':area' => $this->area);       
        $banners = Banner::model()->findAll($criteria);
        
        if(count($banners) > 0 && key_exists($this->template,$templates)){
            $this->render($templates[$this->template],array('banners' => $banners));
        }
    }
}